<?php
//数据提取工具
class DataAction extends Action {
	function index(){		
		$this->display();
	}
	
	function articleList(){
		$app = empty($_REQUEST['appData']) ? 'ask' : $_REQUEST['appData'];

		switch ($app){
			case 'ask':
				$dao = D('Ask', 'ask');
				$field = "askId, title";
				$order = "askId desc";
				break;
			case 'blog':
				$dao = D('Blog', 'blog');
				$field = "blogId, title";
				$order = "blogId desc";
				break;
			case 'bbs':
				$dao = D('Topic', 'bbs');
				$field = "id, title";
				$order = "id desc";
				break;
			default:
				$focus_type = intval($_REQUEST['focus_type']);
				if(!empty($focus_type)){
					$map['type'] = $focus_type;
				}
				$map['recycleId'] = 0;
				
				$wiki = D('Focus', 'wiki')->where($map)->field('wikiId')->findAll();
				//dump(D('Focus', 'wiki')->getLastSql());
				foreach ($wiki as $v){
					$wikiArr[] = $v['wikiId'];
				}
				$wiki = implode(',', $wikiArr);
				
				unset($map);
				$map = $this->_getMap($app);
				$map['id'] = array('in', $wiki);
				
				$list = D('Wiki', 'wiki')->where($map)->field('id, title')->findPage();
				//dump(D('Wiki', 'wiki')->getLastSql());
		}

		if($app != 'wiki'){
			$map = $this->_getMap($app);

			$list = $dao->where($map)->field($field)->order($order)->findPage();
			//dump($dao->getLastSql());
		}
		
		foreach ($list['data'] as $k=>$v){
			$data[$k]['title'] = array_pop($v);
			$data[$k]['id'] = array_pop($v);
		}
		unset($list['data']);

		$this->assign('data', $data);
		$this->assign('list', $list);	
		
		$this->display();	
	}
	
	function _getMap($app){
		$title = t($_REQUEST['title']);
		if(!empty($title)){			
			$map['title'] = array('like', "%$title%");
		}
		
		$status = intval($_REQUEST['status']);
		if(!empty($status)){
			$map['status'] = $status;
		}
		
		$uid = intval($_REQUEST['uid']);
		if(!empty($uid)){
			$map['uid'] = $uid;
		}

		$top = intval($_REQUEST['top']);
		if(!empty($top)){
			$map['top'] = $top;
		}

		$dist = intval($_REQUEST['dist']);
		if(!empty($dist)){
			$map['dist'] = $dist;
		}			
		
		return $map;
	}
}
?>